package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.WorkSpaceService;
import com.sky.vo.BusinessDataVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;

@RestController
@RequestMapping("/admin/workspace")
@Slf4j
@Api(tags = "工作台相关接口")
public class WorkSpaceController {

    @Autowired
    private WorkSpaceService workSpaceService;

    @ApiOperation("工作台今日数据查询")
    @GetMapping("/businessData")
    public Result<BusinessDataVO> businessData() {
        log.info("工作台今日数据查询");
        LocalDateTime now = LocalDateTime.now();

        // 当天开始时间：00:00:00
        Date begin = Date.from(now.truncatedTo(ChronoUnit.DAYS)//截断到“天”级别，保留年月日，时分秒设为0
                .atZone(ZoneId.systemDefault())//// 关联系统默认时区（如Asia/Shanghai）
                .toInstant());/// 转为UTC时间戳（Instant）

        // 当天结束时间：23:59:59
        LocalDateTime endTime = now.truncatedTo(ChronoUnit.DAYS)
                .plusDays(1)// 加1天，变为次日0点
                .minusSeconds(1);// 减1秒，变为当天23:59:59
        Date end = Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant());


        BusinessDataVO businessDataVO = workSpaceService.getBusinessData(begin, end);
        return Result.success(businessDataVO);


    }


    /**
     * 查询订单管理数据
     */
    @GetMapping("/overviewOrders")
    @ApiOperation("查询订单管理数据")
    public Result<OrderOverViewVO> overviewOrders() {
        return Result.success(workSpaceService.getOrderOverView());

    }

    /**
     * 查询菜品总览
     */
    @GetMapping("/overviewDishes")
    @ApiOperation("查询菜品总览")
    public Result<DishOverViewVO> overviewDish() {
        return Result.success(workSpaceService.getDishOverView());
    }

    /**
     * 查询套餐总览
     */
    @GetMapping("/overviewSetmeals")
    @ApiOperation("查询套餐总览")
    public Result<SetmealOverViewVO> overviewSetmeals() {
        return Result.success(workSpaceService.getSetmealOverView());
    }


}
